<?php 
session_start();
if (isset($_POST['id']) && isset($_SESSION['openid'])){ 
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
	if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
	$openid=$_SESSION['openid'];
	$theday=date("Y-m-d");
	$tiao=(int)$_POST['id'];
	$query=$mysqli->query("SELECT count(id) as count FROM `ling` where openid='".$openid."' and theday ='".$theday."'  ");
	$countInfo=$query->fetch_assoc();
	$count=$countInfo['count'];
	
	
	$mysqli->query("insert into l_id(openid,createtime) values('".$openid."','".date("Y-m-d H:i:s")."') ");
	$jid=5;
	$jName='wu';
	if(0 == $count){
	    $city='';
	    
	   /**
	    $query=$mysqli->query("SELECT city FROM `users` where openid='".$openid."' limit 0,1 ");
	    if($query->num_rows>0){
	        $getUser=$query->fetch_assoc();
	        $city=$getUser['city'];
	    }
	    if ('苏州' == $city){
	        $mysqli->query("insert into l_id2(openid,createtime) values('".$openid."','".date("Y-m-d H:i:s")."') ");
	    
	        $queryLid=$mysqli->query("SELECT id FROM `l_id2` where openid='".$openid."' order by id desc limit 0,1 ");
	        $LidInfo=$queryLid->fetch_assoc();
	        if(3 == $LidInfo['id']){
                $jid=1;
                $jName='xxj';
            }
	        $mysqli->query("insert into ling(openid,jid,theday,tiao,createtime) values('".$openid."','".$jid."','".$theday."','".$tiao."','".date("Y-m-d H:i:s")."') ");
	        echo json_encode(array('s'=>'ok','j'=>$jName));
	        exit;
	        
	    }  
	     */
	    
	    $queryLid=$mysqli->query("SELECT id FROM `l_id` where openid='".$openid."' order by id desc limit 0,1 ");
	    $LidInfo=$queryLid->fetch_assoc();
	    $query=$mysqli->query("SELECT name FROM `ling_log` where jid='".$LidInfo['id']."' limit 0,1 ");
	    if($query->num_rows>0){
	        $getLing=$query->fetch_assoc();
	        if(2 == $getLing['name']){
	            //$jid=1;
	            //$jName='xxj';
	        }
	        if(100 == $getLing['name']){
	            $jid=4;
	            $jName='yib';
	        }
	    }
	     
	    //if ('oe2K2jq6xrEGWw0ob3uO236LMmUw' == $openid){
	     //   $jid=4;
	    //    $jName='yib';
	   // }
	     
	    
	     
	    $mysqli->query("insert into ling(openid,jid,theday,tiao,createtime) values('".$openid."','".$jid."','".$theday."','".$tiao."','".date("Y-m-d H:i:s")."') ");
	    echo json_encode(array('s'=>'ok','j'=>$jName));
	    exit;
	}
	
	if(1 == $count){
	    $query=$mysqli->query("SELECT id FROM `share` where openid='".$openid."' and theday ='".$theday."' limit 0,1 ");
	    if($query->num_rows>0){
	        
	        $queryLid=$mysqli->query("SELECT id FROM `l_id` where openid='".$openid."' order by id desc limit 0,1 ");
	        $LidInfo=$queryLid->fetch_assoc();
	        $query=$mysqli->query("SELECT name FROM `ling_log` where jid='".$LidInfo['id']."' limit 0,1 ");
	        if($query->num_rows>0){
	            $getLing=$query->fetch_assoc();
	            if(2 == $getLing['name']){
	                $jid=1;
	                $jName='xxj';
	            }
	            if(100 == $getLing['name']){
	                $jid=4;
	                $jName='yib';
	            }
	        }
 
	        $mysqli->query("insert into ling(openid,jid,theday,tiao,createtime) values('".$openid."','".$jid."','".$theday."','".$tiao."','".date("Y-m-d H:i:s")."') ");
	        
	        echo json_encode(array('s'=>'ok','j'=>$jName));
	        exit;
	    }else{
	         
	        echo json_encode(array('s'=>'less'));
	        exit;
	    }
	}
 
	echo json_encode(array('s'=>'less'));
	exit;
	 
}
?>